<!--输入框-->
<template>
	<zh-form-item
		:ref="prop"
		:label="label"
		:prop="prop"
		:span="span"
		:md="md"
		:sm="sm"
		:xs="xs"
		:lg="lg"
		:xl="xl"
		:offset="offset"
		:push="push"
		:pull="pull"
		:tag="tag"
	>
		<zh-choose-org
			v-model="value"
			v-model:nameValue="myNameValue"
			v-bind="allAttrs"
			:size="mySize"
			:disabled="getDisabled()"
			@change="onChange"
			:orgTypeList="props.orgTypeList"
		>
			<template #[item]="data" v-for="item in Object.keys($slots)">
				<slot :name="item" v-bind="data || {}"></slot>
			</template>
		</zh-choose-org>
	</zh-form-item>
</template>
<script lang="ts" setup>
import { formItemProps, itemProps, itemController } from '../lib/mapController';
// 定义属性
const props = defineProps({
	modelValue: {
		type: [Number, String, Boolean, Array],
		default: '',
	},
	nameValue: {
		type: [String, Array],
		default: undefined,
	},
	...formItemProps,
	...itemProps,
	//模式：multiple 多选
	mode: {
		type: String,
		default() {
			return '';
		},
	},
	orgTypeList: {
		type: Array,
		default: () => {
			return [];
		},
	},
	//最大可选人数
	max: {
		type: Number,
		default: 100,
	},
	//最小选择人数
	min: {
		type: Number,
		default: 0,
	},
});
const attrs = useAttrs();
const emit = defineEmits(['update:modelValue', 'update:nameValue', 'change']);
const allAttrs = computed(() => {
	return Object.assign(props.extend, attrs);
});
const myNameValue = ref(props.nameValue);
const { value, globalSize } = itemController(props, allAttrs.value, emit);
const state = reactive({
	mySize: allAttrs.value.size,
});
// 初始化
globalSize(state);
// 输出
const { mySize } = toRefs(state);
let golbalProps: any = inject('golbalProps', {});
//获取可编辑设置
const getDisabled = () => {
	if (props.disabled === null || props.disabled === undefined) {
		return golbalProps.disabled;
	} else {
		return props.disabled;
	}
};
const onChange = (checkList) => {
	emit('change', checkList);
};
watch(
	() => myNameValue.value,
	() => {
		emit('update:nameValue', myNameValue.value);
	},
	{
		deep: true,
	}
);
</script>
<script lang="ts">
// 声明额外的选项
export default {
	name: 'zh-form-choose-org',
	inheritallAttrs: false,
};
</script>
<style></style>
